package com.example.plat.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.plat.enity.Activity;
import com.example.plat.enity.dto.ActivityCardDto;
import com.example.plat.enity.dto.JudgeActivityDto;
import com.example.plat.exception.AdminException;
import com.example.plat.service.AdminService;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(description = "管理员行为")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    AdminService service;

    @GetMapping("/judge")
    public IPage<JudgeActivityDto> getJudge(@RequestParam(defaultValue = "0") Integer pageNum,
                                            @RequestParam(defaultValue = "10") Integer pageSize) {
        IPage<Activity> page = service.getJudge(pageNum, pageSize);

        return page.convert(u -> {
            JudgeActivityDto v = new JudgeActivityDto();
            BeanUtils.copyProperties(u, v);
            return v;
        });
    }

    @GetMapping("/pass")
    public IPage<JudgeActivityDto> getPass(@RequestParam(defaultValue = "0") Integer pageNum,
                                           @RequestParam(defaultValue = "10") Integer pageSize) {
        IPage<Activity> page = service.getPass(pageNum, pageSize);

        return page.convert(u -> {
            JudgeActivityDto v = new JudgeActivityDto();
            BeanUtils.copyProperties(u, v);
            return v;
        });
    }

    @PutMapping("/{actId}/{flag}")
    public ResponseEntity<String> judgeActivity(@PathVariable Long actId,@PathVariable Boolean flag) throws AdminException {
        service.judgeActivity(actId, flag);

        return ResponseEntity.ok("success!");
    }
}
